<?php

namespace App\Console\Commands;

use App\Jobs\UpdateMovieInfo;
use App\Movie;
use Illuminate\Console\Command;

class SortMovie extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'sort:movie';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '整理电影资源';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $movies = Movie::all();
        foreach ($movies as $movie){
            $name_length = strlen(trim($movie->name_zh));
            if($name_length < 1){
                $job = new UpdateMovieInfo($movie);
                dispatch($job);
            }
        }
        $this->call('queue:listen');
    }
}
